# -*- coding: utf-8 -*-
"""
@Time ： 2022/4/8 11:15
@Auth ： 龙龙
"""
# products = [[“iphone”,6888],[“MacPro”,14800],[“小米6”,2499],[“Coffee”,31],[“Book”,60],[“Nike”,699]]
# a、打印出以下格式
# b、购物车功能：根据的 products 列表写一个循环不断询问用户想买什么，用户选择一个商品编号，就把对应的商品添加到购物车里，最终用户输入 q 退出时，打印购买的商品列表。
# 提示:有 shop_car 和 shop_cost 两个列表，当时输入商品不存在的时候，提示相关错误

products = [
    ["iphone",6888],
    ["MacPro",14800],
    ["小米6",2499],
    ["Coffee",31],
    ["Book",60],
    ["Nike",699]
]
length = len(products)

print('=======商品列表========')
n = 0
for i in (products):
    mun ="\t" + str(i)[1:-1].replace("'","").replace(",","\t\t")
    print(n,mun)
    n += 1


shoping = []
while True:
     shop = input('请输入商品编号')
     if shop.isdigit():
         shop = int(shop)
         if shop >=0 and shop < length:
              shoping.append(products[shop])
              print('你已经添加{}号商品到购物车'.format(products[shop]))
         else:
             print('商品不存在')
     elif shop == 'q':
             print("=====你已经购买以下商品=======")
             shoping = str(shoping)[1:-1].replace("'", "").replace(",", "\t")
             print(shoping)
             break


# 添加购物车提示可以优化下
# 购物车输出也可以优化下
